# Transparent Corruption: The effect of illicit connections and trusted references 
# on the demand for bureaucratic intermediation

# Authors: Jose Ramon Morales-Arilla & Ana Gabriela Ibarra Luces

# SCRIPT 06 - SUMMARY STATISTICS 

# Generate a summary statistics table for the main analysis variables with 
# number of observations, percent of non NA values, mean, sd, min and max

summary_table <- summarytools::descr(tabla_survey %>% select(Y, 'Corruption Suggestion' = Sug_Corr,
                                    'Price' = Precio, 'Link Gestor' = GestLink, 
                                    'Speed' = Rapidez, 'Experience' = Exper,
                                    'Bargain' = bargain, 
                                    'Income source' = income_source,
                                    'Migration thoughts' = mig_thought, 
                                    'Prev. Gestor' = prev_gest),
                                    
            stats = c("n.valid", "pct.valid", "mean", "sd", "min", "max") , 
            transpose = T
) %>% 
  tibble::rownames_to_column( " ")


# EXPORT ------------------------------------------------------------------

write_xlsx(summary_table, 'Data/Output/Tables/06_summary_stats.xlsx', col_names = TRUE)

# ## ----------------------------------------------------------------------

rm(list = setdiff(ls(), c('tabla_survey', 'tab_1', 'tab_2', 'tab_3', 'tab_4', 
                          'tab_1_q', 'tab_2_q', 'tab_3_q', 'tab_h', 'tab_sq', 
                          'reg_1_c', 'reg_5_c', 'reg_9_c', 'reg_1_s', 'reg_1_h', 
                          'Tabla_Att', 'Matriz_Final', 'summary_table')))